package com.neuedu.springmvc.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * @author 金山
 * 项目：springmvc-learn
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2025/3/1810:40
 */
@RestController
public class UploadController {


    @RequestMapping("/upload")
    public String upload(MultipartFile file) throws IOException {

        System.out.println(file.getOriginalFilename());
        System.out.println(file.getSize());
        System.out.println(file.getName());

        String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
        String newFileName = UUID.randomUUID().toString()+ext;

        file.transferTo(new File("D:\\upload",newFileName));
        return "success";

    }


}
